#pragma once
#include <google/protobuf/service.h>
#include "ZooKeeperUtil.h"

class SrpcChannel:public google::protobuf::RpcChannel{
    public:
    SrpcChannel(bool connectNow);
    virtual ~SrpcChannel();
    void CallMethod(const google::protobuf::MethodDescriptor* method,
    google::protobuf::RpcController* controller,
    const google::protobuf::Message* request,
    google::protobuf::Message* response,
    google::protobuf::Closure* done
    ) override;
    private:
    int m_clientfd;
    std::string m_service_name;
    std::string m_ip;
    uint16_t m_port;
    std::string m_method_name;
    int m_idx;
    bool newConnect(const std::string& ip, uint16_t port);
    std::string QueryServiceHost(ZooKeeperClient* zkclient, const std::string& service_name, const std::string& method_name, int &idx);
};